#pragma once

#include "gamescene.h"
#include "GalconCommonTypes.h"
#include "GalconTypes.h"
#include "GameInitInfo.h"
#include "GalconClient.h"
#include "MessageBase.h"
#include "GameStateFwd.h"
#include "FlightInfoFwd.h"

class Game : public QObject
{
   Q_OBJECT
public:
   
public:
    Game(boost::shared_ptr<QGraphicsView> gameView, GameInitInfoPtr gameInitInfo, QObject *parent = NULL); 
    Game(boost::shared_ptr<QGraphicsView> gameView, QObject *parent = NULL);
    void SetGameState(GameStatePtr gameState);
    void LaunchShips(const FlightInfoPtr);
    ~Game();
signals:
    void SendMessage(const Message& );
public slots:
    void StartLocalGame();
    void StartLANGame(GameInitInfoPtr gameInitInfo);
    //void Restrart();
    void Update();
private slots:
   void timerHandler();
   void shipsLaunched(const FlightInfoPtr);
   void shipsArrived(const ShipsArrivedInfoPtr);
private:
   // initializes game
   void initGame();
   void startGame();
   void initScene();
   void initPlanets();
   void initPlayers();
   // initilizes lan game
   void initLANGame();
   void calculateDistancesAndAnglesBtwPlanets();
   void disconnectSignals();
   
   GameScene::Distances m_distances;
   GameScene::Angles m_angles;
   boost::shared_ptr<QGraphicsView> m_gameView;
   boost::shared_ptr<GameScene> m_gameScene;
   PlayerID m_playerID;
   PlayersMapPtr m_players;
   GameInitInfoPtr m_gameInitInfo;
   PlanetsMapPtr m_planets;
   QTimer m_gameTimer;
};

typedef boost::shared_ptr<Game> GamePtr;